home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / challenge / 12.09-Sep96 / Testcode96.09R1.sit / Testcode96.09R1 / 2 Fib app R1 / FibApp.java < prev    next >
Text File  |  1996-08-18  |  415b  |  21 lines

  1. public class FibApp
  2. {
  3.     public static int Fib1(int n,int i,int j)
  4.     {
  5.         if (n==1) return i;
  6.         else if (n==2) return j;
  7.         else if (n==3) return i+j;
  8.         else return Fib1(n-1,j,i+j);    /* really terrible application of recursion for a point */
  9.     }
  10.     
  11.     public static int Fib()
  12.     {
  13.         return Fib1(40,1,1);
  14.     }
  15.  
  16.     public static void main(String argv[])
  17.     {
  18.         System.out.println( "Correct result is "+Integer.toString(Fib() ) );
  19.     }
  20. }
  21.